package com.soilflow.web.controller.soilflow;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.soilflow.common.domain.LandHire;
import com.soilflow.common.domain.LandRent;
import com.soilflow.common.domain.dto.LandRentDto;
import com.soilflow.info.service.ILandRentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.soilflow.common.annotation.Log;
import com.soilflow.common.core.controller.BaseController;
import com.soilflow.common.core.domain.AjaxResult;
import com.soilflow.common.enums.BusinessType;
import com.soilflow.common.utils.poi.ExcelUtil;
import com.soilflow.common.core.page.TableDataInfo;

/**
 * 【租金管理】Controller
 * 
 * @author party
 * @date 2023-09-07
 */
@RestController
@RequestMapping("/land/rent")
public class LandRentController extends BaseController
{
    @Autowired
    private ILandRentService landRentService;

    /**
     * 查询租金列表，如果同一块土地有多条记录，只显示最新那条
     */
//    @PreAuthorize("@ss.hasPermi('system:rent:list')")
    @GetMapping("/list")
    public TableDataInfo list(LandRentDto landRent) {
        startPage();
        List<LandRent> list = landRentService.selectLandRentList(landRent);
        return getDataTable(list);
    }
    /**
     * 查询历史租金
     */
    @GetMapping("/listhistory")
    public TableDataInfo listhistory(LandRent landRent) {
        startPage();
        List<LandRent> list = landRentService.selectLandRenthistory(landRent);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:rent:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LandRentDto landRent)
    {
        List<LandRent> list = landRentService.selectLandRentList(landRent);
        ExcelUtil<LandRent> util = new ExcelUtil<LandRent>(LandRent.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rent:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(landRentService.selectLandRentById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:rent:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LandRent landRent)
    {
        return toAjax(landRentService.insertLandRent(landRent));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:rent:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LandRent landRent)
    {
        return toAjax(landRentService.updateLandRent(landRent));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:rent:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(landRentService.deleteLandRentByIds(ids));
    }
}
